#ifndef CLONGSCREENSHOT_H
#define CLONGSCREENSHOT_H

#include <QObject>
#include <QQmlEngine>
#include <QQuickWindow>
#include <QWindow>

class CLongScreenShot : public QObject
{
    Q_OBJECT
public:
    explicit CLongScreenShot(QQmlEngine *engine, QObject *parent = nullptr);

public slots:
    //启动长截图
    bool start(QObject *object);

    void mousePress(QWindow *window, int x, int y);
    void mouseMove(QWindow *window, int x, int y);
    void mouseRelease(QWindow *window, int x, int y);

    QList<QQuickWindow *> findWindw(QQmlEngine *engine);
signals:
    void atEnd();  //滚动到底部了
protected:
    bool eventFilter(QObject* obj, QEvent* event) override;
private:
    int sameMaxRowCnt(QPixmap &pixmap);

    //给定窗口，滚动指定高度，找到滚动区的开始y和结束y值。
    //找不到滚动区范围空 QRect()
    QRect findScrollArea(QWindow *target, int scrollHeight);
    void scrollWindow(QWindow *window, QPointF start, QPointF end);
    QImage grabWindow(QWindow *target);
private:
    QQmlEngine *m_pEngine = nullptr;

    QObject *m_pCopyTarget = nullptr;
};

#endif // CLONGSCREENSHOT_H
